﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Common;
using WpfApp1.Chat.UserComponents;

namespace WpfApp1.Chat.UserPage
{
    /// <summary>
    /// HomePage.xaml 的交互逻辑
    /// </summary>
    public partial class HomePage : Page
    {
        public HomePage()
        {
            InitializeComponent();

            this.Loaded += HomePage_Loaded;
        }

        private async void HomePage_Loaded(object sender, RoutedEventArgs e)
        {
            var result = await WebSocketHelper.GetChatWebSocketList();
            //MessageBox.Show(result);
        }

        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            // 创建新的 UserControlMessageSent 实例
            var newMessage = new UserControlMessageSent();
            newMessage.HorizontalAlignment = HorizontalAlignment.Right;
            newMessage.MessageViewModel = new Models.Chat.MessageModel()
            {
                Message = SendMessageTextBox.Text,
                MessageTime = DateTime.Now.ToString("dddd HH:mm:ss"),
            };

            // 设置其属性（例如，文本或其他信息）
            // newMessage.SomeProperty = "新的消息内容";

            // 将新的控件添加到 StackPanel 中
            MessageStackPanel.Children.Add(newMessage);

            // 滚动到 StackPanel 的底部，显示最新消息
            MessageScrollViewer.ScrollToBottom();
        }

    }
}
